import {NgModule, Optional, SkipSelf} from '@angular/core';
import {HttpClientModule} from '@angular/common/http';
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
import {SharedModule} from '../share/shared.module';
import {AppRoutingModule} from './app-routing.module';
import {MatIconRegistry} from '@angular/material';
import {DomSanitizer} from '@angular/platform-browser';
import {loadSvgResource} from '../util/svg.util';
import {AlertDialogComponent} from '../component/dialog/alert.dialog.component';
import {LoadingDialogComponent} from '../component/dialog/loading.dialog.component';
import {AuthGuardService} from '../service/auth.guard.service';
import {HomeGuardService} from '../service/home.guard.service';
import {MarkdownModule} from 'ngx-markdown';
import {HeaderComponent} from '../component/header/header.component';
import {FooterComponent} from '../component/footer/footer.component';
import {AvatarComponent} from '../component/avatar/avatar.component';

@NgModule({
  declarations: [
    HeaderComponent,
    FooterComponent,
    AvatarComponent,
  ],
  imports: [
    SharedModule,
    AppRoutingModule,
    HttpClientModule,
    BrowserAnimationsModule,
    MarkdownModule.forRoot(),
  ],
  exports: [
    AppRoutingModule,
    HeaderComponent,
    FooterComponent,
    AvatarComponent,
  ],
  entryComponents: [AlertDialogComponent, LoadingDialogComponent],
  providers: [AuthGuardService, HomeGuardService, {
    provide: 'BASE_CONFIG',
    useValue: {
      baseUrl: 'http://localhost:7290/api',
      // baseUrl: 'http://zzyitj.xyz:7290/api'
    }
  }]
})

export class CoreModule {
  constructor(@Optional() @SkipSelf() parent: CoreModule, ir: MatIconRegistry, ds: DomSanitizer) {
    if (parent) {
      throw new Error('CoreModule on load, dont reload');
    }
    loadSvgResource(ir, ds);
  }
}
